package com.inco.cloud.server1.controller;

import com.inco.cloud.common.util.SecuityUtils;
import com.inco.cloud.server1.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
public class UserController {

    @Autowired
    private Environment env;

//    @Autowired
//    private ConsumerTokenServices consumerTokenServices;

    //注入服务
    @Autowired
    private UserService userService;

    @Autowired
    private SecuityUtils secuityUtils;
    /**
     * 返回用户信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/me")
    public User me() {
        return secuityUtils.getCurrentUser();
    }

    @ResponseBody
    @RequestMapping("/server-port")
    public String serverPort() {
        return env.getProperty("server.port");
    }

    @ResponseBody
    @RequestMapping("/hello-appname")
    public String helloAppName(String appName) {
        return String.format("hello 欢迎访问我 %s",appName);
    }

    /**
     * 添加用户
     * @param username
     * @return
     */
    @ResponseBody
    @RequestMapping("/addUser")
    public Integer addUser(String userId,String username, HttpServletRequest request){
        return userService.addUser(userId,username);
    }

}
